package traitementRequetes;

import java.util.ArrayList;

public class EtudeRequete {

	public String recupererConceptPrincipal(String requete) {
		String concept = "concept non trouvé";

		int debutConcept = requete.indexOf("?") + 1;
		int finConcept = requete.indexOf(" ", debutConcept);
		concept = requete.substring(debutConcept, finConcept);
		return concept;
	}

	public ArrayList<String> recupererAxes(String requete) {
		ArrayList<String> listeAxes = new ArrayList<String>();

		int finDeclarationAxes = requete.indexOf("WHERE");
		int debutAxe = requete.indexOf("?") + 1;
		int finAxe = requete.indexOf(" ", debutAxe);

		while (debutAxe < finDeclarationAxes) {
			listeAxes.add(requete.substring(debutAxe, finAxe));
			debutAxe = requete.indexOf("?", finAxe) + 1;
			finAxe = requete.indexOf(" ", debutAxe);
		}
		return listeAxes;
	}

	// Probablement inutile. 
	public boolean verifierRequeteSPARQL(String requete) {
		boolean requeteValable = false;
		// Pour étudier le contenu de la requête, on va d'abord la passer en
		// majuscule
		String requeteUp = requete.toUpperCase();
		if (requeteUp.contains("?") && (requeteUp.contains("SELECT"))) {
			requeteValable = true;
		}
		return requeteValable;
	}

}
